package cn.springspace.kotlinapp.serializer

import cn.springspace.app.enums.EventTypeEnum
import com.fasterxml.jackson.core.JsonParser
import com.fasterxml.jackson.databind.DeserializationContext
import com.fasterxml.jackson.databind.JsonDeserializer
import org.apache.commons.lang3.StringUtils

class EventTypeDeserializer : JsonDeserializer<String>() {

    override fun deserialize(jsonParser: JsonParser, ctxt: DeserializationContext): String {
        var value = jsonParser.valueAsInt;
        for (enum in EventTypeEnum.values()) {
            if (StringUtils.equals(enum.value, value.toString())) {
                return enum.labelCn;
            }
        }
        return EventTypeEnum.UNKNOWN.labelCn;
    }
}